#include "TimerMgr.h"
#include "MinuteTimer.h"
#include <boost/bind.hpp>

#pragma comment(lib, "timer_module.lib")
CTimerMgr::CTimerMgr(void)
{
    m_pTimerModule = NULL;
}


CTimerMgr::~CTimerMgr(void)
{
    if (m_pTimerModule)
    {
        m_pTimerModule->release();
        m_pTimerModule = NULL;
    }
}

bool CTimerMgr::Init()
{
    m_pTimerModule = utility::timer_util::get_timer_module();
    if (m_pTimerModule == NULL)
        return false;
    utility::timer_util::timer * pTimer1 = m_pTimerModule->create_timer("timer1");
    if (pTimer1 == NULL)
        return false;
    pTimer1->set_interval(60000);
    pTimer1->set_event(boost::bind(&CMinuteTimer::NotifyAll, CMinuteTimer::Instance()));
    pTimer1->start();
    return true;
}

bool CTimerMgr::Run()
{
    if (m_pTimerModule)
        return m_pTimerModule->run() > 0;
    return false;
}
